﻿using System;
using System.Web.UI.WebControls;

public partial class master_Default : System.Web.UI.Page
{
    protected string initstring = "";
   

    protected void Page_Load(object sender, EventArgs e)
    {

        ds_名师讲堂.tb_名师风采DataTable dt;
        ds_名师讲堂.tb_名师风采Row dr;
        using (ds_名师讲堂TableAdapters.tb_名师风采TableAdapter da = new ds_名师讲堂TableAdapters.tb_名师风采TableAdapter())
        {
            dt = da.GetDataBy显示在首页();
        }
        System.Text.StringBuilder sb = new System.Text.StringBuilder();
        sb.Append("var order5 = new Array(''");
        for (int i = 0; i < dt.Rows.Count; i++)
        {
            sb.AppendFormat(",{0}", i);
        }
        sb.Append(");");
        sb.AppendFormat("count={0};", dt.Rows.Count);
        for (int i = 0; i < dt.Rows.Count; i++)
        {
            sb.AppendFormat("order5[{0}]='{1}';", i + 1, (i + 1).ToString());
        }
        for (int i = 0; i < dt.Rows.Count; i++)
        {
            dr = dt.Rows[i] as ds_名师讲堂.tb_名师风采Row;

            sb.AppendFormat("imgLink5[{0}] = 'aspx/teacher/one.aspx?id={1}';", i + 1, dr.名师ID);
            sb.AppendFormat(" imgUrl5[{0}] = '{1}';", i + 1, dr.虚目录.Substring(2));
            sb.AppendFormat("imgText5[{0}] = '{1}';", i + 1, dr.姓名);
        }
        initstring = sb.ToString();
    }

    protected void rpt讲堂动态_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        HyperLink hy = e.Item.FindControl("hy") as HyperLink;
        DateTime dt = DateTime.Parse(hy.ToolTip);
        if (dt > DateTime.Now)
        {
            change(hy, "aspx/tang/one.aspx", 9);
            hy.Text = string.Format("【预告】{0}", hy.Text);
        }
        else
        {
            change(hy, "aspx/tang/one.aspx", 12);
        }
    }

    protected void rpt新闻中心_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        change(e.Item.FindControl("hy") as HyperLink, "aspx/news/one.aspx", 13);
    }

    protected void rpt通知公告_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        change(e.Item.FindControl("hy") as HyperLink, "aspx/notice/one.aspx", 13);
    }

    protected void rpt视频中心_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        change(e.Item.FindControl("hy") as HyperLink, "aspx/video/one.aspx", 20);
    }

    /// <summary>
    /// 限制hy的最长字数
    /// </summary>
    /// <param name="hy"></param>
    /// <param name="url"></param>
    /// <param name="length"></param>
    private void change(HyperLink hy, string url, int length)
    {
        string text = hy.Text;
        if (hy.Enabled == true)
        {
            length -= 2;
        }
        hy.Enabled = true;
        if (hy.Visible == true)
        {
            hy.ForeColor = System.Drawing.Color.Red;
            hy.Font.Bold = true;
        }
        else
        {
            hy.Visible = true;
        }
        if (text.Length > length)
        {
            text = text.Substring(0, length);
            hy.Text = string.Format("{0}…", text);
        }

        hy.NavigateUrl = string.Format("{0}?id={1}", url, hy.NavigateUrl);
    }
    protected void txt讲堂简介_DataBinding(object sender, EventArgs e)
    {
        Label lbl = sender as Label;
        if (lbl.Text.Length > 170)
        {
            lbl.Text = lbl.Text.Substring(0, 170) + "……";
        }
    }
}